package com.tjp.eight.ui.activity;


import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;
import android.view.View;

import com.tjp.eight.R;
import com.tjp.eight.comment.AppManager;
import com.tjp.eight.ui.fragment.detail.FragmentArticleDetail;
import com.umeng.analytics.MobclickAgent;
import com.umeng.socialize.UMShareAPI;

import me.imid.swipebacklayout.lib.SwipeBackLayout;
import me.imid.swipebacklayout.lib.ViewDragHelper;
import me.imid.swipebacklayout.lib.app.SwipeBackActivity;

/**
 * Created by Administrator on 2017/2/15.
 */

public class ActivityFragmentDetail extends SwipeBackActivity {
    SwipeBackLayout swipeBackLayout;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        AppManager.getAppManager().AddActivity(this);
        setContentView(R.layout.acty_article_detail);
        findViewById(R.id.rl_head_nav).setVisibility(View.GONE);
        changeFragment(new FragmentArticleDetail());
        swipeBackLayout = getSwipeBackLayout();
        swipeBackLayout.setEdgeTrackingEnabled(ViewDragHelper.EDGE_LEFT);
    }

    public void changeFragment(Fragment f) {
        changeFragment(f, false);
    }

    public void changeFragment(Fragment f, boolean isCanBack) {
        FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
        ft.replace(R.id.acty_article_detail_content, f);
        if (isCanBack)
            ft.addToBackStack(null);
        ft.commitAllowingStateLoss();
    }

    @Override
    public void onBackPressed() {
        super.onBackPressed();
        AppManager.getAppManager().finishActivity(this);
    }


    public void finish() {
        super.finish();
        overridePendingTransition(R.anim.in_from_right, R.anim.out_from_right);
    }

    @Override
    protected void onResume() {
        super.onResume();
        MobclickAgent.onResume(this);
    }

    @Override
    protected void onPause() {
        super.onPause();
        MobclickAgent.onResume(this);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        UMShareAPI.get(this).onActivityResult(requestCode, resultCode, data);
    }
}
